/*
 * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
 *
 * SPDX-License-Identifier: Apache-2.0.
 *
 * @Date: 2021-04-07 09:53:07
 * @LastEditTime: 2021-04-07 17:54:21
 * @Description:  This files is for uart register function
 *
 * @Modify History:
 *  Ver   Who        Date         Changes
 * ----- ------     --------    --------------------------------------
 */

#include "pl011_uart_hw.h"

/**
 * @name: Pl011SendByte
 * @msg:
 * @return {*}
 * @param {u32} addr
 * @param {u8} Byte
 */
void Pl011SendByte(u32 addr, u8 byte)
{
    while (FT_UART_ISTRANSMITFULL(addr))
    {
        ;
    }
    FT_UART_WRITEREG32(addr, UARTDR_OFFSET, (u32)byte);
}

/**
 * @name: Pl011RecvByte
 * @msg:
 * @return {*}
 * @param {u32} addr
 */
u8 Pl011RecvByte(u32 addr)
{
    u32 RecievedByte;
    while (FT_UART_ISRECEIVEDATA(addr))
    {
        ;
    }
    RecievedByte = FT_UART_READREG32(addr, UARTDR_OFFSET);
    return RecievedByte;
}

/**
 * @name: Pl011GetChar
 * @msg:
 * @return {*}
 * @param {u32} addr
 */
u8 Pl011GetChar(u32 addr)
{
    u32 RecievedByte;
    if (FT_UART_ISRECEIVEDATA(addr))
    {
        return 0xff;
    }
    RecievedByte = FT_UART_READREG32(addr, UARTDR_OFFSET);
    return RecievedByte;
}
